package graph

import "math/rand"

/**
邻接矩阵表示法
*/

type VerTextType byte //顶点类型
type ArcType int      //边的权值类型

//Adjacency Matrix Graph
type AMGraph struct {
	VerTexType []VerTextType //顶点表
	ArcType    [][]ArcType   //邻接矩阵
	verNum     int           //图的顶点数
	arcNum     int           //图的边数
}

func CreateAMGraph(verList []VerTextType) *AMGraph {
	max := len(verList)
	arcNum := 0
	arcList := make([][]ArcType, max)
	for i := 0; i < max; i++ {
		arcCol := make([]ArcType, max)
		arcList[i] = arcCol
		for j := 0; j < max; j++ {
			if i == j {
				arcCol[j] = 0
			} else if i > j {
				arcCol[j] = arcList[j][i]
			} else {
				value := rand.Int() % 2
				if value != 0 {
					arcNum++
				}
				arcCol[j] = ArcType(value)
			}
		}
	}
	return &AMGraph{
		VerTexType: verList,
		ArcType:    arcList,
		verNum:     max,
		arcNum:     arcNum,
	}
}
